#pragma once

#include <iostream>
#include<string>
#include<unistd.h>
#include <pthread.h>
using namespace std;

class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex)
    :_mutex(mutex)
    {}
    void Lock()
    {
        pthread_mutex_lock(_mutex);
    }
    void UnLock()
    {
        pthread_mutex_unlock(_mutex);
    }

private:
    pthread_mutex_t* _mutex;
};

class mutex_guard
{
public:
    mutex_guard(pthread_mutex_t* mutex)
    :_m(mutex)//会调用对应的构造函数
    {
        _m.Lock();
    }

    ~mutex_guard()
    {
        _m.UnLock();
    }

private:
    Mutex _m;//自定义成员变量 
};
